package sys.xui

import javax.swing.JFrame
import groovy.ui.Console
import groovy.ui.ConsoleTextEditor
import groovy.swing.SwingBuilder
import javax.swing.JTabbedPane
import java.net.URL

public class XuiBrowser extends JFrame {

  private SwingBuilder swing = new SwingBuilder()
  private JTabbedPane tabbedPane = null
  private XomBrowser xomBrowser = null
  private Console console = null
  //private StarBrowser starBrowser = null

  private void initialize() {
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE)
    setExtendedState(JFrame.MAXIMIZED_BOTH)
    addExtensions()
  }

  private void addExtensions() {
    // Groovy Console
    console = new groovy.ui.Console()
    // XOM
    xomBrowser = new XomBrowser()
    //xomBrowser.openUrl("/")
    xomBrowser.openUrl("/Users/mac/dev/xui")
    tabbedPane = swing.tabbedPane() {
      //panel(title:'XOM Browser')
      widget(title:'XOM Browser', xomBrowser)
    }
    // STAR
    add(tabbedPane)
  }

  public XuiBrowser() {
    super("XUI")
    initialize()
  }

  public void showGroovyConsole(File file) {
    try {
      console.loadScriptFile(file)
      console.run()
    } catch(e) {
      e.printStackTrace()
    }
  }

  public void showGroovyConsole() {
    console.run()
  }

  public static void main(args) {
     XuiBrowser xuiBrowser = new XuiBrowser()
     xuiBrowser.show()
     System.in.eachLine() { line -> if(line.equals("exit")) System.exit(0) }
  }

}
